(define (map f xs)
  (if (null? xs)
      '()
      (cons (f (car xs))
            (map f (cdr xs)))))

(define (foldl f z xs)
  (if (null? xs)
      z
      (foldl f (f (car xs) z) (cdr xs))))

(define (range n)
  (define (go i)
    (if (> i n)
        '()
        (cons i (go (+ i 1)))))
  (go 1))

;; 1² + 2² + 3² + 4² = 30
(let* ([sqr (lambda (x) (* x x))]
       [sqrs (map sqr (range 4))])
  (foldl + 0 sqrs))
